package com.wuyou.demo;

import com.mysql.cj.util.StringUtils;

import java.io.*;
import java.sql.*;

public class MsqSqlExecDemo {


    public static void main(String[] args) throws IOException {
        System.out.println("111111111111111");

        String url = "jdbc:mysql://localhost:3306/msq_test";
        String username = "root";
        String pwd = "root";
        StringBuilder sb = new StringBuilder();
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

            Connection connection = DriverManager.getConnection(url, username, pwd);
            Statement statement = connection.createStatement();

            FileReader file = new FileReader("C:\\Users\\Administrator\\Desktop\\归档\\store_front_user.sql");
            BufferedReader br = new BufferedReader(file);
            boolean flag = false;

            statement.execute("use msq_test;");
            int count = 1;
            while (br.ready()) {
                String s = br.readLine();
                if (s.indexOf("--") != -1) {
                    continue;
                }
                sb.append(s);
                if (s.indexOf(";") != -1) {
                    statement.execute(sb.toString());
                    System.out.println("第" + count + "次执行 -> " + sb);
                    sb = new StringBuilder("");
                    count++;
                }
            }
        } catch (Exception e) {
            System.out.println(sb);
            e.printStackTrace();
        }
    }
}
